<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/modules/cms/front/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>用户注册</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="decorator" content="ems_${site.theme}_front" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="description" content="${site.description}" />
<meta name="keywords" content="${site.keywords}" />
<link rel="stylesheet" href="${ctxStatic}/sdsng/lib/weui.min.css">
<link rel="stylesheet" href="${ctxStatic}/sdsng/css/jquery-weui.css">
<link rel="stylesheet" href="${ctxStatic}/sdsng/css/style.css">
</head>
<body ontouchstart>
<!--主体-->
<header class="wy-header">
  <div class="wy-header-icon-back"><span></span></div>
  <div class="wy-header-title">用户注册</div>
</header>

<form id="registerForm" action="${ctx }/regist">
<input type="hidden" name="siteId" value="${site.id }">
<div class="weui-content">
  <div class="weui-cells weui-cells_form wy-address-edit">
  <!----有验证码的情况---->
  <!--  <div class="weui-cell weui-cell_vcode">
      <div class="weui-cell__hd"><label class="weui-label wy-lab">手机号</label></div>
      <div class="weui-cell__bd"><input class="weui-input" type="tel" placeholder="请输入手机号"></div>
      <div class="weui-cell__ft"><button class="weui-vcode-btn">获取验证码</button></div>
    </div>
    <div class="weui-cell weui-cell_vcode">
      <div class="weui-cell__hd"><label class="weui-label wy-lab">验证码</label></div>
      <div class="weui-cell__bd"><input class="weui-input" type="number" placeholder="请输入验证码"></div>
      <div class="weui-cell__ft"><img class="weui-vcode-img" src="./images/vcode.jpg"></div>
    </div>-->
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label wy-lab">登录名</label></div>
      <div class="weui-cell__bd"><input class="weui-input" type="text" id="loginName" name="loginName" placeholder="输入您的登录名"></div>
    </div>
	<div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label wy-lab">手机号码</label></div>
      <div class="weui-cell__bd"><input class="weui-input" type="text" id="mobile" name="mobile"  placeholder="输入您的手机号码"></div>
    </div>
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label wy-lab">姓名</label></div>
      <div class="weui-cell__bd"><input class="weui-input" type="text" name="name" placeholder="输入您的姓名"></div>
    </div>
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label wy-lab">设置密码</label></div>
      <div class="weui-cell__bd"><input class="weui-input" type="password" id="password" name="password" placeholder="请输入密码"></div>
    </div>
    <div class="weui-cell">
      <div class="weui-cell__hd"><label class="weui-label wy-lab">确认密码</label></div>
      <div class="weui-cell__bd"><input class="weui-input" type="password" id="passwordCfm" name="passwordCfm" placeholder="请再次输入密码"></div>
    </div>
  </div>
  <label for="weuiAgree" class="weui-agree">
    <input id="weuiAgree" type="checkbox" class="weui-agree__checkbox"/>
    <span class="weui-agree__text">阅读并同意<a href="${ctx }/frontProtocol?siteId=${site.id}" target="_blank">《注册协议》</a></span>
  </label>
  <div class="weui-btn-area"><a href="#" onclick="doRegister();" class="weui-btn weui-btn_warn" style="background:#1ec80d">注册</a></div>
  <div class="weui-cells__tips t-c font-12">登陆账号为您输入的用户名或者手机号码</div>
  <div class="weui-cells__tips t-c pd-10"><a href="${ctx }/frontProtocol?siteId=${site.id}" target="_blank" class="weui-cell_link font-12">查看注册协议</a></div>
  
</div>
</form>

<script src="${ctxStatic}/sdsng/lib/jquery-2.1.4.js"></script> 
<script src="${ctxStatic}/sdsng/lib/fastclick.js"></script>
<script type="text/javascript" src="${ctxStatic}/sdsng/js/jquery.Spinner.js"></script>
<script src="${ctxStatic}/sdsng/js/base.js"></script>
<script>
  $(function() {
    FastClick.attach(document.body);
  });
  
  function doRegister()
  {
	  
	  var loginName = $("#loginName").val();
	  var mobile = $("#mobile").val();
	  var password = $("#password").val();
	  var passwordCfm = $("#passwordCfm").val();
	  if(!loginName)
	  {
	  	alert("请输入用户名");
	  	return;
	  }
	  if(!mobile)
	  {
	  	alert("请输入手机号码");
	  	return;
	  }
	  
	  if(!REG_MOBILE_PATTERN.test(mobile)){
		alert("输入的手机号码格式错误，请重新输入");
		return;
	  }
	  
	  if(!password)
	  {
	  	alert("请输入密码");
	  	return;
	  }
	  if(password.length < 6)
	  {
		  alert("密码长度不能小于6位");
		  return;
	  }
	  if(password != passwordCfm)
	  {
	  	alert("输入两次密码不一致，请重新输入");
	  	return;
	  }
	  
	  var result = false;
		// 校验用户名和手机号码是否重复
		$.ajax({
		       type: "POST",
		       url: ctx+"/checkExists",
		       dataType: "text",
		       data:"loginName="+loginName + "&mobile=" + mobile,
			   async: false,
		       success: function(jsonMajor){
			       // 转换为json对象
			       jsonMajor = eval('(' + jsonMajor + ')');
			       
			       var isLoginName = jsonMajor['loginName'];
			       var isMobile = jsonMajor['mobile'];
			       
			       if("yes" == isLoginName || "yes" == isMobile)
		    	   {
			    	   alert("登陆名" + loginName + "和手机号码" + mobile + "都已经存在，请修改。");
			    	   result = true;
		    	   }else
		    	   {
				       if("yes" == isLoginName)
			    	   {
				    	   // $("#messageBox").text("手机号为'" + mobile + "'且名称含'" + name + "'的学员已经存在。");
				    	   // $("#messageBox").show();
				    	   
				    	   //$("#loginNameTip").html("登陆名" + loginName + "已经存在。");
				    	   //$("#loginNameTip").show();
				    	   alert("登陆名" + loginName + "已经存在，请修改。");
				    	   result = true;
			    	   }
				       /* else
				       {
				    	   $("#loginNameTip").hide();
				       } */
				       
				       if("yes" == isMobile)
			    	   {
				    	   // $("#messageBox").text("手机号为'" + mobile + "'且名称含'" + name + "'的学员已经存在。");
				    	   // $("#messageBox").show();
				    	   
				    	  // $("#mobileTip").html("手机号码" + mobile + "已经存在。");
				    	  //$("#mobileTip").show();
				    	  alert("手机号码" + mobile + "已经存在，请修改。");
				    	   result = true;
			    	   }
				       /* else
				       {
				    	   $("#mobileTip").hide();
				       } */
				       //$("#messageBox").text("输入有误，请先更正。");
		    	   }
		       }
		    });
		
	  var isChecked = $("#weuiAgree").is(":checked");
	  if(!isChecked)
	  {
		  alert("请先阅读并同意注册协议");
	  	  return;
	  }
		  
	  if(!result)
	  {
		  document.getElementById("registerForm").submit();
	  }
	  
  }
  
</script>

<script src="${ctxStatic}/sdsng/js/jquery-weui.js"></script>
</body>
</html>